<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
</head>
<body>
    <div id="app"></div>
    <script>
        setInterval(show,1000)
       function show(){
        var app = document.getElementById("app")
        var time = "2021-10-19 8:30:00"
        // 1 获取当前时间毫秒数
        var d = new Date();
        var startTime = d.getTime();
        // 2 获取活动开始的毫秒数
        var endTime = new Date(time).getTime();
        // 3 得到中间间隔的秒数
        var times = (endTime-startTime)/1000;
        console.log(times)
        var d = parseInt(times/60/60/24);//天
        var h = parseInt(times / 60 / 60 % 24); //时
        var m = parseInt(times / 60 % 60); //分
        var s = parseInt(times % 60); //秒
        var sum = handleNum(d)+":"+handleNum(h)+":"+handleNum(m)+":"+handleNum(s);
        console.log(sum);
        app.innerHTML = sum;
       }
        function handleNum(num){
            if(num<10){
                num = "0"+num;
            }
            return num;
        }
    </script>
</body>
</html>